<template>
    <div class="banner-box" v-if="banner.length">
        <el-carousel :interval="4000" height="500px" v-show="!isPhone" indicator-position="none">
            <el-carousel-item v-for="(item, index) in banner" :key="index">
                <a :href="item.path ? item.path : ''" class="slider">
                    <div class="title" v-if="item.is_text">
                        <div v-for="(itm, idx) in item.list" :key="idx">{{ itm }}</div>
                    </div>
                    <div class="img-box" v-else>
                        <img :src="item.ImgUrl" :alt="item.title">
                    </div>
                    <div class="watermark">@zs.duan</div>
                </a>
            </el-carousel-item>
        </el-carousel>
        <van-swipe @change="onChangeSwiper" v-show="isPhone" >
            <van-swipe-item v-for="(item, index) in banner" :key="index">
                <a :href="item.path ? item.path : ''" class="slider">
                    <div class="title" v-if="item.is_text">
                        <div v-for="(itm, idx) in item.list" :key="idx">{{ itm }}</div>
                    </div>
                    <div class="img-box" v-else>
                        <img :src="item.ImgUrl" :alt="item.title">
                    </div>
                    <!-- <div class="watermark">@zs.duan</div> -->
                </a>
            </van-swipe-item>
            <template #indicator>
                <div class="custom-indicator">{{ current + 1 }}/{{ banner.length }}</div>
            </template>
        </van-swipe>

    </div>
</template>
<script>
import { isPhone } from '../../utils/index';
export default {
    props: {
        banner: {
            type: Array,
            defalut: () => {
                return []
            }
        }
    },
    data() {
        return {
            isPhone: false,
            current: 0
        }
    },
    mounted() {
        this.getIsPhone();
    },
    methods: {
        /**获取是否在手机端*/
        async getIsPhone() {
            this.isPhone = await isPhone();
            window.addEventListener('resize', async () => {
                this.isPhone = await isPhone();
                if (!this.isPhone && this.showSearch) {
                    this.cancelSearch()
                }
            });
        },
        /**改变swiper*/
        onChangeSwiper(index) {
            this.current = index;
        }
    }
}
</script>
<style lang="scss" scoped>
.banner-box {
    box-shadow: 0 4px 8px 6px rgba(7, 17, 21, 0.06);
    border-radius: 8px;
    margin-bottom: 20px;
    overflow: hidden;
    box-sizing: border-box;

    .slider {
        width: 100%;
        height: 100%;
        background-color: rgb(32, 30, 30);
        text-align: center;
        color: #fff;
        font-size: 50px;
        display: flex;
        justify-content: center;
        align-items: center;
        overflow: hidden;
        position: relative;
        border-radius: 8px;
        overflow: hidden;

        .img-box {
            width: 100%;
            height: 100%;

            img {
                width: 100%;
                height: 100%;
                object-fit: cover;
            }
        }
    }

    .watermark {
        position: absolute;
        right: 5px;
        color: rgba(255, 255, 255, 0.3);
        font-size: 12px;
        bottom: 10px;
        z-index: 10;
    }

    .custom-indicator {
        position: absolute;
        right: 5px;
        bottom: 5px;
        padding: 2px 5px;
        font-size: 12px;
        color: #fff;
        background: rgba(0, 0, 0, 0.1);
    }
}
@media screen and (max-width: 768px) {
    .banner-box{
        margin-bottom: 0;
        height: 200px;
        border-radius: 0;
        /deep/.van-swipe{
            height: 100%;
        }
        .slider{
            border-radius: 0;
            .img-box{
                img{
                    height: 100%;
                }
            }
        }
    }
}
</style>